cd C:\Documents' and Settings'\MA-SIMULATION1\My' Documents'\Downloads\hershey
f=fopen('hershey','r');

figure(clf);
offset=[0 0];
spacing=5;

axis equal

l=[];

startline = 90;
endline=116;
for jj=1:startline-1
    textline=fgetl(f);
end

jj=startline-1;
letter=cell(0);
while ~feof(f) && jj<endline
    jj=jj+1;
    textline=fgetl(f);

    symbol_number = str2double(strtrim(textline(1:5)));
    num_vertices =  str2double(strtrim(textline(6:8)));
    width = range(textline(9:10)-'R');
%     for ii=1:length(l)
%         delete(l(ii));
%     end
    coords = [];
    lines=cell(0);
    l=[];
    for ii=11:2:length(textline)
        if strcmp(textline(ii:ii+1),' R') 
            l(end+1) = line(coords(:,1)+offset(1),...
                     coords(:,2)+offset(2));%,'linewidth',5);
            lines{end+1}=coords;
            coords=[];
            
        else
            coords(end+1,:)=(textline(ii:ii+1)-'R').*[1 -1];
        end
        
        if ii==length(textline)-1
            l(end+1) = line(coords(:,1)+offset(1),...
                     coords(:,2)+offset(2));%,'linewidth',5);
            lines{end+1}=coords;
        end
    end
    letter{end+1}=lines;
    title(num2str(jj));
    %pause(0.2);
    offset=offset+[width+spacing, 0];
    if mod(jj,26)==0 %offset(1)>500
        offset = [0,offset(2)-30];
    end
%     cont=input('Stop?\n','s');
%     if strcmpi(cont,'y')
%        break
%     end
end

fclose(f);

%%
clf;
axis equal
%%
nl=letter;
nl{1}{1}=[letter{1}{1}(2,:); letter{1}{2}(:,:)];
nl{1} = [nl{1}(1); nl{1}(3)];

clf;
axis equal
for ii=1:length(letter{1})
end
ii=1;
line(nl{1}{ii}(:,1),nl{1}{ii}(:,2));

